class Solution {
public:
    vector<string> ret;
    string path;

    vector<string> letterCasePermutation(string s) {
        dfs(s, 0);
        return ret;
    }

    void dfs(string str, int pos)
    {
        if (path.size() == str.size())
        {
            ret.push_back(path);
            return;
        }

        path += str[pos];
        dfs(str, pos + 1);
        path.pop_back();

        if (str[pos] >= 'a' && str[pos] <= 'z')
        {
            path += toupper(str[pos]);
            dfs(str, pos + 1);
            path.pop_back();
        }
        else if (str[pos] >= 'A' && str[pos] <= 'Z')
        {
            path += tolower(str[pos]);
            dfs(str, pos + 1);
            path.pop_back();
        }
    }
};